{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "f66dee42",
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.neighbors import kneighbors_graph\n",
    "import numpy as np\n",
    "import torch\n",
    "\n",
    "def LCS(X,Si,nk):\n",
    "    S = kneighbors_graph(X, nk, mode='distance', include_self=False, metric='euclidean').todense()\n",
    "    S[S==0]=np.inf\n",
    "    S = np.array(np.exp(-S/(Si)))\n",
    "    S = torch.from_numpy(S).to(torch.float32)\n",
    "    #Dii\n",
    "    Ds = torch.diag(torch.sum(S, dim=1))\n",
    "    return S,Ds"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
